/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package au.edu.swin.unilearn;

import au.edu.swin.unilearn.submission.*;
import au.edu.swin.unilearn.assignment.*;
import au.edu.swin.unilearn.students.*;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;

/**
 *
 * @author DidierLeung
 */
public class ViewStatusManagedBean
{
    @EJB
    private StudentSessionRemote studentSession;
    private String studentID;
    private String args;

    public String checkWork()
    {
        List<Submission> allSubmittedWork = studentSession.getSubmissions(args);
        if (allSubmittedWork.size() == 0)
        {
            return "none";
        }
        else
        {
            return "display";
        }
    }

    public List<SubmittedWork> getSubmittedWork()
    {
        List<SubmittedWork> submitWorks = new ArrayList();
        List<Submission> allSubmittedWork = studentSession.getSubmissions(args);
        for (Submission s : allSubmittedWork)
        {
            Assignment a = s.getAssignmentObj();

            SubmittedWork sw = new SubmittedWork(a.getAssignment_no() + " - " + a.getAssignment_name(),
                                                 s.getSubmission_status(),
                                                 convertResultToStr(s.getResults(), a.getSubmission_status()));
            submitWorks.add(sw);
        }

        return submitWorks;
    }

    private String convertResultToStr(double d, String status)
    {
        if (status.equals("UNMARKED"))
        {
            return "-/100";
        }
        else
        {
            double newD = d * 100;
            return (new Double(newD)).toString() + "/100";
        }
    }

    public String getStudentID()
    {
        return studentID;
    }

    public void setStudentID(String studentID)
    {
        this.studentID = studentID;
    }

    public String getArgs()
    {
        return args;
    }

    public void setArgs(String args)
    {
        this.args = args;
    }
}
